/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUIv2;

import java.awt.event.MouseEvent;
import java.io.File;
import java.util.List;

import javax.swing.JOptionPane;

import jsonObjects.Profile;
import serverHandling.SessionObjects;

@SuppressWarnings("serial")
public class FileAttributeReplacePanel extends javax.swing.JPanel {

    public FileAttributeReplacePanel() {
        initComponents();
    }

    private void initComponents() {
        List<Profile> activProfTab = SessionObjects.getProfiles();
        Object[][] futureMenuItems;
        if (activProfTab != null) {
            futureMenuItems = new Object[activProfTab.size()][activProfTab.size()];
            for (int i = 0; i < activProfTab.size(); i++) {
                futureMenuItems[i][0] = activProfTab.get(i).getName();
            }
        } else
            futureMenuItems = new Object[0][0];

        fileAttributeReplacePanel = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTable6 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();

        jTable6.setModel(new javax.swing.table.DefaultTableModel(
                futureMenuItems,
                new String[]{
                        "Profile"
                }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable6.getColumnModel().getColumn(0).setResizable(false);

        jScrollPane6.setViewportView(jTable6);

        jButton2.setText("Next");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout fileAttributeReplacePanelLayout = new javax.swing.GroupLayout(fileAttributeReplacePanel);
        fileAttributeReplacePanel.setLayout(fileAttributeReplacePanelLayout);
        fileAttributeReplacePanelLayout.setHorizontalGroup(
                fileAttributeReplacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(fileAttributeReplacePanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(fileAttributeReplacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, fileAttributeReplacePanelLayout.createSequentialGroup()
                                                .addGap(0, 0, Short.MAX_VALUE)
                                                .addComponent(jButton2)))
                                .addContainerGap())
        );
        fileAttributeReplacePanelLayout.setVerticalGroup(
                fileAttributeReplacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(fileAttributeReplacePanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2)
                                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(fileAttributeReplacePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addComponent(fileAttributeReplacePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
        );
    }

    private void jButton2ActionPerformed(MouseEvent evt) {
        FileAttributeProfileFileListGUI replacePanel = null;
        if (jTable6.getSelectedRowCount() == 1) {

            int row = jTable6.getSelectedRow();
            int column = jTable6.getSelectedColumn();
            String urObjctInCell = (String) jTable6.getValueAt(row, column);
            final Profile profTmp = SessionObjects.getProfileByName(urObjctInCell);

            if (profTmp == null)
                JOptionPane.showMessageDialog(null, "Nie odnaleziona atrybutu dla wybranego profilu!");

            else {
                replacePanel = new FileAttributeProfileFileListGUI(profTmp);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Nalezy wybrac profil!");
        }


        javax.swing.JPanel parenPanel = (javax.swing.JPanel) fileAttributeReplacePanel.getParent();

        parenPanel.removeAll();
        javax.swing.GroupLayout parenPanelLayot = new javax.swing.GroupLayout(parenPanel);
        parenPanel.setLayout(parenPanelLayot);
        parenPanelLayot.setHorizontalGroup(
                parenPanelLayot.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(replacePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
        );
        parenPanelLayot.setVerticalGroup(
                parenPanelLayot.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(replacePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
        );
        parenPanel.add(replacePanel);
        parenPanel.revalidate();
        parenPanel.repaint();
    }

    javax.swing.JPanel fileAttributeReplacePanel;
    javax.swing.JButton jButton2;
    javax.swing.JScrollPane jScrollPane6;
    javax.swing.JTable jTable6;
    File file;
    Profile profile;
}
